/**
 * 
 */
package com.enerccio.commonJ.tests;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

import com.enerccio.commonJ.objects.ConsCell;
import com.enerccio.commonJ.objects.Symbol;

public class commonJTests {
	
	ConsCell consCellPrintTest1data;
	ConsCell consCellPrintTest2data;
	ConsCell consCellPrintTest3data;
	ConsCell consCellPrintTest4data;
	ConsCell consCellPrintTest5data;
	ConsCell consCellPrintTest6data;
	
	Symbol symbolTest1data;
	Symbol symbolTest2data;
	Symbol symbolTest3data;
	Symbol symbolTest4data;
	
	@Before
	public void setUp() throws Exception {
		consCellPrintTest1data = new ConsCell(1, 2);
		consCellPrintTest2data = new ConsCell(ConsCell.NIL, consCellPrintTest1data);
		consCellPrintTest3data = ConsCell.list(1, 2, 3);
		consCellPrintTest4data = ConsCell.list(consCellPrintTest3data, consCellPrintTest3data, "X");
		consCellPrintTest5data = ConsCell.list(4);
		consCellPrintTest6data = ConsCell.list(5, 1);
		
		symbolTest1data = Symbol.newKeyword("ANNE");
		symbolTest2data = Symbol.newGensym("0");
		symbolTest3data = Symbol.newKeyword("ANNE");
		symbolTest4data = Symbol.newGensym("0");
	}
	
	/**
	 * Tests various print methods for cons cells / lists
	 */
	@Test
	public void consCellPrintTest(){
		assertEquals("Testing cons print. Expected result: (1 . 2); ", 
				"(1 . 2)", consCellPrintTest1data.toString());
		assertEquals("Testing cons print. Expected result: (NIL 1 . 2); ", 
				"(NIL 1 . 2)", consCellPrintTest2data.toString());
		assertEquals("Testing list print. Expected result: (1 2 3); ", 
				"(1 2 3)", consCellPrintTest3data.toString());
		assertEquals("Testing list print. Expected result: ((1 2 3) (1 2 3) X); ", 
				"((1 2 3) (1 2 3) X)", consCellPrintTest4data.toString());
		assertEquals("Testing list print. Expected result: (NIL NIL NIL NIL); ", 
				"(NIL NIL NIL NIL)", consCellPrintTest5data.toString());
		assertEquals("Testing list print. Expected result: (1 1 1 1 1); ", 
				"(1 1 1 1 1)", consCellPrintTest6data.toString());
	}
	
	/**
	 * Tests various cons cell for isList predicate.
	 */
	@Test
	public void consCellIsListTest(){
		assertTrue("Testing first cons cell. Expected false.", !consCellPrintTest1data.isList());
		assertTrue("Testing second cons cell. Expected false.", !consCellPrintTest2data.isList());
		assertTrue("Testing third cons cell. Expected true.", consCellPrintTest3data.isList());
		assertTrue("Testing fourth cons cell. Expected true.", consCellPrintTest4data.isList());
		assertTrue("Testing sixth cons cell. Expected true.", consCellPrintTest5data.isList());
		assertTrue("Testing seventh cons cell. Expected true.", consCellPrintTest6data.isList());
	}

	/**
	 * Tests various symbol expressions and operations.
	 */
	@Test
	public void symbolTest(){
		assertEquals("Testing printout form of keyword. Expected :ANNE.", ":ANNE",
				symbolTest1data.toString());
		assertEquals("Testing printout form of gemsym. Expected |GENSYM: 0|.", "|GENSYM: 0|",
				symbolTest2data.toString());
		assertTrue("Testing that newKeyword is interned.", symbolTest1data == symbolTest3data);
		assertTrue("Testing that newGensym is never interned.", symbolTest2data != symbolTest4data);
	}
}
